<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Jumbotron Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/css/jumbotron.css" rel="stylesheet">
    <style>
        .alert{
            display: none;
        }
    </style>

    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<%include header.ejs%>

    <div class="container" style="margin-top: 100px;">
        <form id="register_form" method="post">
            <div class="form-group">
                <label for="exampleInputEmail1">用户名</label>
                <input type="text" class="form-control"  placeholder="用户名" name="name">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">密码</label>
                <input type="password" class="form-control" placeholder="Password" name="password">
            </div>

            <span id="submit" class="btn btn-default">Submit</span>
        </form>
        <p class="alert alert-success" role="alert" id="reg_fail">注册成功！</p>
        <p class="alert alert-danger" role="alert" id="reg_fail">注册失败！</p>
        <p class="alert alert-warning" role="alert" id="reg_fail">用户名已存在！</p>
    </div>

<!-- Placed at the end of the document so the pages load faster -->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.js"></script>
<script>
    $(function () {
        $('#submit').click(function () {
            $.ajax({
                url:'/doRegister',
                method:'post',
                data:$('#register_form').serialize(),
                success:function (result) {
                    if(result === -3){
                        $('.alert-danger').show();
                    }else if(result === -1){
                        $('.alert-warning').show();
                        setTimeout(function () {
                            location.href='/';
                        },1500);
                    }else if(result === 1){
                        $('.alert-success').show();
                    }
                    console.log(result);
                }
            })
        });
    })
</script>
</body>
</html>
